﻿Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Windows.Threading
Imports GalaSoft.MvvmLight
Imports GalaSoft.MvvmLight.Command
Imports FL_8x0.Common.SystemData
Imports FL_8x0.Common.Database
Imports FL_8x0.Common.mdlDevice
Imports FL_8x0.Common.mdlLPUAddress
Imports FL_8x0.Model
Imports FL_8x0.FL_830.Model

Namespace FL_8x0.FL_830.ViewModel

    Public Class SystemViewModel
        Inherits ViewModelBase

        Private _systemModel As SystemModel    '系统设置参数
        Private _rs232 As SerialPortModel      'RS232串口参数
        Private _rs485 As SerialPortModel      'RS485串口参数
        Private _netModel As NetModel          '网络参数

        Private _isModbusOk As Boolean         'Modbus 工作正常

        Private _reason As String              '修改原因
        Private _enableSave As Boolean         '保存有效

        Private _applyCommand As RelayCommand   '点击“确认”触发命令
        Private _cancelCommand As RelayCommand  '点击“取消”触发命令


        Private _portNameList As ObservableCollection(Of String)        '串口号列表
        Private _pointList As ObservableCollection(Of String)           '小数点列表
        Private _ePointList As ObservableCollection(Of String)          '科学计数法小数点列表
        Private _inList As ObservableCollection(Of String)              'IN输入节点可选功能
        Private _outList As ObservableCollection(Of String)             'OUT输出节点可选功能
        Private _netModeList As ObservableCollection(Of String)         'NET工作状态
        Private _baudRateList As ObservableCollection(Of String)        '波特率列表
        Private _stopBitslList As ObservableCollection(Of UShort)       '停止位列表
        Private _dataBitsList As ObservableCollection(Of UShort)        '数据位列表
        Private _parityList As ObservableCollection(Of Char)          '校验位列表
        Private _rs232ProtocolList As ObservableCollection(Of ProtocolItem)   'RS232协议列表
        Private _rs485ProtocolList As ObservableCollection(Of ProtocolItem)   'RS485协议列表
        Private _netProtocolList As ObservableCollection(Of String)     'NET协议列表
        Private _endCharList As ObservableCollection(Of String)         '结尾字符列表

        Private _timer As DispatcherTimer                               '定时任务

        Private _updateTimeCommand As RelayCommand                      '更新时间触发命令

        Private _enableAutoSave As Boolean                              '自动保存曲线



        Public Sub New()
            InitListSource()
            FillModel()
            IsModbusOk = uLPU.IsModbusOK()
            Timer = New DispatcherTimer()
            If IsModbusOk Then
                Timer.Interval = TimeSpan.FromMilliseconds(500)
                AddHandler Timer.Tick, AddressOf TimeFlash
                Timer.Start()
            End If
            EnableAutoSave = g_udtOtherSet.blnAutoSaveWave
            ApplyCommand = New RelayCommand(Sub() Apply())
            CancelCommand = New RelayCommand(Sub() Cancel())
            UpdateTimeCommand = New RelayCommand(Sub() UpdateTime())
        End Sub



        '=====================================================================
        '函 数 名: UpdateTime
        '参    数: 
        '返 回 值:
        '功能描述: 更新设备时间
        '=====================================================================
        Private Sub UpdateTime()
            uLPU.OUT_WriteUint16(1, ADDR_OUT_RTC_YEAR, Now().Year)
            uLPU.OUT_WriteUint16(1, ADDR_OUT_RTC_MONTH, Now().Month)
            uLPU.OUT_WriteUint16(1, ADDR_OUT_RTC_DAY, Now().Day)
            uLPU.OUT_WriteUint16(1, ADDR_OUT_RTC_HOUR, Now().Hour)
            uLPU.OUT_WriteUint16(1, ADDR_OUT_RTC_MINUTE, Now().Minute)
            uLPU.OUT_WriteUint16(1, ADDR_OUT_RTC_SECOND, Now().Second)
            uLPU.OUT_WriteUint16(1, ADDR_OUT_RTC_UPDATE, 1)
        End Sub

        '=====================================================================
        '函 数 名: TimeFlash
        '参    数: 
        '返 回 值:
        '功能描述: 定时刷新时间
        '=====================================================================
        Private Sub TimeFlash(sender As Object, e As EventArgs)
            SystemModel.Time = CStr(uLPU.IN_ReadUint16(1, ADDR_IN_RTC_YEAR)) & "-" &
                               CStr(uLPU.IN_ReadUint16(1, ADDR_IN_RTC_MONTH)) & "-" &
                               CStr(uLPU.IN_ReadUint16(1, ADDR_IN_RTC_DAY)) & " " &
                               CStr(uLPU.IN_ReadUint16(1, ADDR_IN_RTC_HOUR)) & ":" &
                               CStr(uLPU.IN_ReadUint16(1, ADDR_IN_RTC_MINUTE)) & ":" &
                               CStr(uLPU.IN_ReadUint16(1, ADDR_IN_RTC_SECOND))
        End Sub


        '=====================================================================
        '函 数 名: InitListSource
        '参    数: 
        '返 回 值:
        '功能描述: 初始化列表
        '=====================================================================
        Private Sub InitListSource()
            InList = New ObservableCollection(Of String) From {
                "BUBL", "Fitting", "CAL1=>CAL2", "Fitting=>CAL2", "START(开标准漏孔)", "小泄漏偏倚校准", "大泄漏偏倚校准",
                "START(开TANK容积)", "STEP单步运行", "CH1通道选择", "CH2通道选择"
                }

            OutList = New ObservableCollection(Of String) From {
                "READY", "RUN", "END", "BNG", "SNG", "LNG", "FNG", "延时1环节", "充气1环节", "充气2环节", "平衡1环节", "平衡2环节",
                "小漏检测环节", "大漏检测环节", "延时2环节", "排气环节", "延时3环节", "BUBL检测", "Fitting检测", "CAL1检测", "CAL2检测",
                "START(开标准漏孔)检测", "小泄漏偏倚校准", "大泄漏偏倚校准", "气缸", "旁路充气", "旁路排气1", "旁路排气2",
                "START(开TANK容积)检测", "STEP单步运行", "环节配置"
                }

            BaudRateList = New ObservableCollection(Of String) From {
                "1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"
                }
            DataBitsList = New ObservableCollection(Of UShort) From {
                7, 8
                }
            StopBitslList = New ObservableCollection(Of UShort) From {
                1, 2
                }
            ParityList = New ObservableCollection(Of Char) From {
                "O", "E", "N"
                }
            NetModeList = New ObservableCollection(Of String) From {
                "UDP Client", "TCP Client", "UDP Server", "TCP Server"
                }
            Rs232ProtocolList = New ObservableCollection(Of ProtocolItem) From {
                New ProtocolItem(0, "Modbus ASCII"), New ProtocolItem(1, "Modbus RTU"),
                New ProtocolItem(2, "Modbus TCP"), New ProtocolItem(6, "RESP"),
                New ProtocolItem(7, "800-M1"), New ProtocolItem(8, "800-M4"),
                New ProtocolItem(11, "SCAN-T1"), New ProtocolItem(12, "SCAN-T2"),
                New ProtocolItem(13, "SCAN-T3"), New ProtocolItem(14, "SCAN-T4"),
                New ProtocolItem(15, "PRINTER-T1"), New ProtocolItem(16, "PRINTER-T2"),
                New ProtocolItem(17, "PRINTER-T3"), New ProtocolItem(18, "PRINTER-T4")
                }
            Rs485ProtocolList = New ObservableCollection(Of ProtocolItem) From {
                New ProtocolItem(0, "Modbus ASCII"), New ProtocolItem(1, "Modbus RTU"),
                New ProtocolItem(2, "Modbus TCP"), New ProtocolItem(3, "EXT-AIC"),
                New ProtocolItem(15, "PRINTER-T1")
                }
            NetProtocolList = New ObservableCollection(Of String) From {
                "Modbus ASCII", "Modbus RTU", "Modbus TCP"
                }

            PortNameList = New ObservableCollection(Of String)()
            For i = 1 To 32
                PortNameList.Add("COM" & i)
            Next

            PointList = New ObservableCollection(Of String) From {
                "0", "0.0", "0.00", "0.000", "0.0000", "0.00000"
                }
            EPointList = New ObservableCollection(Of String) From {
                "0E+0", "0.0E+0", "0.00E+0", "0.000E+0", "0.0000E+0", "0.00000E+0"
                }
            EndCharList = New ObservableCollection(Of String) From {
                "Cr", "Lf", "CrLf"
                }
        End Sub


        '=====================================================================
        '函 数 名: FillModel
        '参    数: 
        '返 回 值:
        '功能描述: 数据填充
        '=====================================================================
        Private Sub FillModel()
            Dim udtSystemModel As SystemModel = New SystemModel
            udtSystemModel.AutoSaveWave = g_udtOtherSet.blnAutoSaveWave
            udtSystemModel.SavePath = g_udtOtherSet.strAutoSaveWavePath
            udtSystemModel.GpAutoStretch = g_udtOtherSet.blnAutoAxisY
            udtSystemModel.GpMax = g_udtOtherSet.sngMaxAxisY
            udtSystemModel.GpMin = g_udtOtherSet.sngMinAxisY
            udtSystemModel.DpAutoStretch = g_udtOtherSet.blnAutoAxisY2
            udtSystemModel.DpMax = g_udtOtherSet.sngMaxAxisY2
            udtSystemModel.DpMin = g_udtOtherSet.sngMinAxisY2


            udtSystemModel.MidwayJudgment = uLPU.OUT_ReadUint16(1, ADDR_OUT_MID_JUDGE) <> 0
            udtSystemModel.UFlashSave = uLPU.OUT_ReadUint16(1, ADDR_OUT_USB_SAVE_EN) <> 0
            udtSystemModel.ExitDetectionTip = User_ReadPublicValue("退出泄漏检测提示", False)
            udtSystemModel.SaveRecordTip = User_ReadPublicValue("导出报告提示", False)
            udtSystemModel.ExitAppTip = User_ReadPublicValue("程序退出提示", False)
            udtSystemModel.Username = User_ReadPublicValue("默认用户名", "")
            udtSystemModel.Password = User_ReadPublicValue("默认密码", "")

            udtSystemModel.PressurePoint = g_udtOtherSet.uint直压_Point
            udtSystemModel.LeakPoint = g_udtOtherSet.uint漏率_Point

            udtSystemModel.EnableScanningGun = g_udtOtherSet.blnScanGuns
            udtSystemModel.AutoStart = g_udtOtherSet.blnAutoStart
            udtSystemModel.PortName = g_udtOtherSet.uintPortName
            udtSystemModel.BaudRate = g_udtOtherSet.uintBaudRate
            udtSystemModel.EndChar = g_udtOtherSet.uintEndChar

            udtSystemModel.In1 = uLPU.OUT_ReadUint16(1, ADDR_OUT_IO1_INPUT_TYPE)
            udtSystemModel.Out1 = uLPU.OUT_ReadUint16(1, ADDR_OUT_IO1_OUTPUT_TYPE)
            udtSystemModel.In2 = uLPU.OUT_ReadUint16(1, ADDR_OUT_IO2_INPUT_TYPE)
            udtSystemModel.Out2 = uLPU.OUT_ReadUint16(1, ADDR_OUT_IO2_OUTPUT_TYPE)

            udtSystemModel.Model = uLPU.IN_ReadString(1, ADDR_IN_MODEL, 20)
            udtSystemModel.Sn = uLPU.IN_ReadString(1, ADDR_IN_SN, 20)
            udtSystemModel.Version = Format(CSng(uLPU.IN_ReadUint16(1, ADDR_IN_SOFT_VER)) / 100, "0.00")
            Me.SystemModel = udtSystemModel

            Dim udtRs232 As SerialPortModel = New SerialPortModel
            udtRs232.Protocol = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS232_PROT)
            udtRs232.Id = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS232_MODBUS_ID)
            udtRs232.BaudRate = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS232_BAUDRATE)
            udtRs232.DataBits = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS232_DATABITS)
            udtRs232.StopBits = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS232_STOPBITS)
            udtRs232.Parity = Convert.ToChar(uLPU.OUT_ReadUint16(1, ADDR_OUT_RS232_PARITY))
            Me.Rs232 = udtRs232

            Dim udtRs485 As SerialPortModel = New SerialPortModel
            udtRs485.Protocol = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS485_PROT)
            udtRs485.Id = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS485_MODBUS_ID)
            udtRs485.BaudRate = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS485_BAUDRATE)
            udtRs485.DataBits = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS485_DATABITS)
            udtRs485.StopBits = uLPU.OUT_ReadUint16(1, ADDR_OUT_RS485_STOPBITS)
            udtRs485.Parity = Convert.ToChar(uLPU.OUT_ReadUint16(1, ADDR_OUT_RS485_PARITY))
            Me.Rs485 = udtRs485

            Dim net As NetModel = New NetModel
            net.NetMode = uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_NET_MODE)
            net.Protocol = uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_PROT)
            net.LocalPort = uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_LOCAL_PORT)
            net.LocalIp = uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_A1) & "." &
                          uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_A2) & "." &
                          uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_A3) & "." &
                          uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_A4)


            net.RemotePort = uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_REMOTE_PORT)
            net.RemoteIp = uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_B1) & "." &
                           uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_B2) & "." &
                           uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_B3) & "." &
                           uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_B4)

            net.Mask = uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_C1) & "." &
                       uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_C2) & "." &
                       uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_C3) & "." &
                       uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_C4)

            net.Gateway = uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_D1) & "." &
                          uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_D2) & "." &
                          uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_D3) & "." &
                          uLPU.OUT_ReadUint16(1, ADDR_OUT_WIRED_IP_D4)
            NetModel = net

        End Sub


        '=====================================================================
        '函 数 名: Apply
        '参    数: 
        '返 回 值:
        '功能描述: 数据存库，更新设备参数
        '=====================================================================
        Private Sub Apply()

            If CheckInput() Then
                SystemModel.AutoSaveWave = EnableAutoSave
                g_udtOtherSet.blnAutoSaveWave = SystemModel.AutoSaveWave
                User_WritePublicValue("自动保存曲线", SystemModel.AutoSaveWave, Reason)

                If g_udtOtherSet.blnAutoSaveWave Then
                    g_udtOtherSet.strAutoSaveWavePath = SystemModel.SavePath
                    User_WritePublicValue("曲线自动保存目录", SystemModel.SavePath, Reason)
                End If


                g_udtOtherSet.blnAutoAxisY = SystemModel.GpAutoStretch
                User_WritePublicValue("曲线直压Y轴自动伸缩", SystemModel.GpAutoStretch, Reason)
                If g_udtOtherSet.blnAutoAxisY Then
                    g_udtOtherSet.sngMaxAxisY = SystemModel.GpMax
                    User_WritePublicValue("Y轴最大", SystemModel.GpMax, Reason)
                    g_udtOtherSet.sngMinAxisY = SystemModel.GpMin
                    User_WritePublicValue("Y轴最小", SystemModel.GpMin, Reason)
                End If


                g_udtOtherSet.blnAutoAxisY2 = SystemModel.DpAutoStretch
                User_WritePublicValue("曲线差压Y轴自动伸缩", SystemModel.DpAutoStretch, Reason)
                If g_udtOtherSet.blnAutoAxisY2 Then
                    g_udtOtherSet.sngMaxAxisY2 = SystemModel.DpMax
                    User_WritePublicValue("Y轴最大", SystemModel.DpMax, Reason)
                    g_udtOtherSet.sngMinAxisY2 = SystemModel.DpMin
                    User_WritePublicValue("Y轴最小", SystemModel.DpMin, Reason)
                End If


                g_udtOtherSet.uint直压_Point = SystemModel.PressurePoint
                User_WritePublicValue("压力小数点", SystemModel.PressurePoint, Reason)
                g_udtOtherSet.uint漏率_Point = SystemModel.PressurePoint
                User_WritePublicValue("漏率小数点", SystemModel.LeakPoint, Reason)

                User_WritePublicValue("退出泄漏检测提示", SystemModel.ExitDetectionTip, Reason)
                User_WritePublicValue("导出报告提示", SystemModel.SaveRecordTip, Reason)
                User_WritePublicValue("程序退出提示", SystemModel.ExitAppTip, Reason)

                g_udtOtherSet.strUserName = SystemModel.Username
                User_WritePublicValue("默认用户名", SystemModel.Username, Reason)
                g_udtOtherSet.strUserName = SystemModel.Password
                User_WritePublicValue("默认密码", SystemModel.Password, Reason)

                g_udtOtherSet.blnScanGuns = SystemModel.EnableScanningGun
                User_WritePublicValue("扫描枪有效", SystemModel.EnableScanningGun, Reason)
                g_udtOtherSet.blnAutoStart = SystemModel.AutoStart
                User_WritePublicValue("扫描后自动启动", SystemModel.AutoStart, Reason)
                g_udtOtherSet.uintBaudRate = SystemModel.BaudRate
                User_WritePublicValue("扫描枪_波特率", SystemModel.BaudRate, Reason)
                g_udtOtherSet.uintPortName = SystemModel.PortName
                User_WritePublicValue("扫描枪_串口号", SystemModel.PortName, Reason)
                g_udtOtherSet.uintEndChar = SystemModel.EndChar
                User_WritePublicValue("扫描枪_结尾", SystemModel.EndChar, Reason)


                If uLPU.IsModbusOK() Then
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_MID_JUDGE, IIf(SystemModel.MidwayJudgment, 1, 0))
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_USB_SAVE_EN, IIf(SystemModel.UFlashSave, 1, 0))


                    uLPU.OUT_WriteUint16(1, ADDR_OUT_IO1_INPUT_TYPE, SystemModel.In1)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_IO1_OUTPUT_TYPE, SystemModel.Out1)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_IO2_INPUT_TYPE, SystemModel.In2)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_IO2_OUTPUT_TYPE, SystemModel.Out2)


                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS232_PROT, Rs232.Protocol)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS232_MODBUS_ID, Rs232.Id)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS232_DATABITS, Rs232.DataBits)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS232_STOPBITS, Rs232.StopBits)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS232_PARITY, Convert.ToUInt16(Rs232.Parity))


                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS485_PROT, Rs485.Protocol)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS485_MODBUS_ID, Rs485.Id)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS485_DATABITS, Rs485.DataBits)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS485_STOPBITS, Rs485.StopBits)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_RS485_PARITY, Convert.ToUInt16(Rs485.Parity))


                    uLPU.OUT_WriteUint16(1, ADDR_OUT_WIRED_NET_MODE, NetModel.NetMode)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_WIRED_PROT, NetModel.Protocol)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_WIRED_LOCAL_PORT, NetModel.LocalPort)
                    uLPU.OUT_WriteUint16(1, ADDR_OUT_WIRED_REMOTE_PORT, NetModel.RemotePort)

                    Dim A As String() = NetModel.LocalIp.Split(".")
                    Dim B As String() = NetModel.RemoteIp.Split(".")
                    Dim C As String() = NetModel.Mask.Split(".")
                    Dim D As String() = NetModel.Gateway.Split(".")

                    For i = 0 To 3
                        uLPU.OUT_WriteUint16(1, ADDR_OUT_WIRED_IP_A1 + i, A(i))
                        uLPU.OUT_WriteUint16(1, ADDR_OUT_WIRED_IP_B1 + i, B(i))
                        uLPU.OUT_WriteUint16(1, ADDR_OUT_WIRED_IP_C1 + i, C(i))
                        uLPU.OUT_WriteUint16(1, ADDR_OUT_WIRED_IP_D1 + i, D(i))
                    Next
                End If
                Reason = ""
                MsgBox("参数保存成功", MsgBoxStyle.OkOnly, "提示")
            End If
        End Sub


        '=====================================================================
        '函 数 名: Cancel
        '参    数: 
        '返 回 值:
        '功能描述: 取消 回填数据
        '=====================================================================
        Private Sub Cancel()
            FillModel()
            EnableAutoSave = SystemModel.AutoSaveWave
        End Sub

        Private Function CheckInput() As Boolean

            If String.IsNullOrEmpty(Reason) Then
                log.WriteLogError("输入参数检查", "请填写修改原因！")
                Return False
            End If

            SystemModel.AutoSaveWave = EnableAutoSave
            If SystemModel.AutoSaveWave Then
                If SystemModel.SavePath = "" Then
                    log.WriteLogError("输入参数检查", "[曲线自动保存目录]不能为空！")
                    Return False
                End If

                If Directory.Exists(SystemModel.SavePath) = False Then
                    log.WriteLogError("输入参数检查", "[曲线自动保存目录]" & SystemModel.SavePath & "不存在！")
                    Return False
                End If
            End If

            If Not SystemModel.SavePath.EndsWith("\") Then
                SystemModel.SavePath &= "\"
            End If

            If Not SystemModel.GpAutoStretch Then
                If Not CheckTextNumber("直压Y轴最大", SystemModel.GpMax, 99999, -99999) Then
                    Return False
                End If

                If Not CheckTextNumber("直压Y轴最小", SystemModel.GpMin, 99999, -99999) Then
                    Return False
                End If

                Dim TOLERANCE As Single = 0.000001
                If Math.Abs(SystemModel.GpMax - 0) < TOLERANCE And Math.Abs(SystemModel.GpMin - 0) < TOLERANCE Then
                    If Math.Abs(SystemModel.GpMax - SystemModel.GpMin) < TOLERANCE Then
                        log.WriteLogError("输入参数检查", "[直压Y轴最大]必须大于[直压Y轴最小]！")
                    End If
                End If
            End If

            If Not SystemModel.DpAutoStretch Then
                If Not CheckTextNumber("差压Y轴最大", SystemModel.DpMax, 99999, -99999) Then
                    Return False
                End If

                If Not CheckTextNumber("差压Y轴最小", SystemModel.DpMin, 99999, -99999) Then
                    Return False
                End If

                Dim TOLERANCE As Single = 0.000001
                If Math.Abs(SystemModel.DpMax - 0) < TOLERANCE And Math.Abs(SystemModel.DpMin - 0) < TOLERANCE Then
                    If Math.Abs(SystemModel.DpMax - SystemModel.DpMin) < TOLERANCE Then
                        log.WriteLogError("输入参数检查", "[差压Y轴最大]必须大于[差压Y轴最小]！")
                    End If
                End If
            End If


            If uLPU.IsModbusOK() Then
                If Not CheckTextNumber("RS232 Modbus ID", Rs232.Id, 254, 1) Then
                    Return False
                End If

                If Not CheckTextNumber("RS485 Modbus ID", Rs485.Id, 254, 1) Then
                    Return False
                End If
                If Not CheckTextNumber("本地端口", NetModel.LocalPort, 65535, 1) Then
                    Return False
                End If

                If Not CheckIP("本地IP", NetModel.LocalIp) Then
                    Return False
                End If

                If Not CheckTextNumber("远程端口", NetModel.RemotePort, 65535, 1) Then
                    Return False
                End If

                If Not CheckIP("远程IP", NetModel.RemoteIp) Then
                    Return False
                End If
                If Not CheckIP("网关", NetModel.Gateway) Then
                    Return False
                End If
                If Not CheckIP("子网掩码", NetModel.Mask) Then
                    Return False
                End If
            End If
            Return True
        End Function

        Public Property SystemModel As SystemModel
            Get
                Return _systemModel
            End Get
            Set
                _systemModel = Value
                RaisePropertyChanged()
            End Set
        End Property

        Public Property Rs232 As SerialPortModel
            Get
                Return _rs232
            End Get
            Set
                _rs232 = Value
                RaisePropertyChanged()
            End Set
        End Property

        Public Property Rs485 As SerialPortModel
            Get
                Return _rs485
            End Get
            Set
                _rs485 = Value
                RaisePropertyChanged()
            End Set
        End Property

        Public Property NetModel As NetModel
            Get
                Return _netModel
            End Get
            Set
                _netModel = Value
                RaisePropertyChanged()
            End Set
        End Property

        Public Property BaudRateList As ObservableCollection(Of String)
            Get
                Return _baudRateList
            End Get
            Set(value As ObservableCollection(Of String))
                _baudRateList = value
            End Set
        End Property

        Public Property StopBitslList As ObservableCollection(Of UShort)
            Get
                Return _stopBitslList
            End Get
            Set(value As ObservableCollection(Of UShort))
                _stopBitslList = value
            End Set
        End Property

        Public Property DataBitsList As ObservableCollection(Of UShort)
            Get
                Return _dataBitsList
            End Get
            Set(value As ObservableCollection(Of UShort))
                _dataBitsList = value
            End Set
        End Property

        Public Property ParityList As ObservableCollection(Of Char)
            Get
                Return _parityList
            End Get
            Set(value As ObservableCollection(Of Char))
                _parityList = value
            End Set
        End Property

        Public Property NetModeList As ObservableCollection(Of String)
            Get
                Return _netModeList
            End Get
            Set(value As ObservableCollection(Of String))
                _netModeList = value
            End Set
        End Property

        Public Property Rs232ProtocolList As ObservableCollection(Of ProtocolItem)
            Get
                Return _rs232ProtocolList
            End Get
            Set(value As ObservableCollection(Of ProtocolItem))
                _rs232ProtocolList = value
            End Set
        End Property

        Public Property Rs485ProtocolList As ObservableCollection(Of ProtocolItem)
            Get
                Return _rs485ProtocolList
            End Get
            Set(value As ObservableCollection(Of ProtocolItem))
                _rs485ProtocolList = value
            End Set
        End Property

        Public Property NetProtocolList As ObservableCollection(Of String)
            Get
                Return _netProtocolList
            End Get
            Set(value As ObservableCollection(Of String))
                _netProtocolList = value
            End Set
        End Property

        Public Property InList As ObservableCollection(Of String)
            Get
                Return _inList
            End Get
            Set(value As ObservableCollection(Of String))
                _inList = value
            End Set
        End Property

        Public Property OutList As ObservableCollection(Of String)
            Get
                Return _outList
            End Get
            Set(value As ObservableCollection(Of String))
                _outList = value
            End Set
        End Property

        Public Property PointList As ObservableCollection(Of String)
            Get
                Return _pointList
            End Get
            Set
                _pointList = Value
            End Set
        End Property

        Public Property EPointList As ObservableCollection(Of String)
            Get
                Return _ePointList
            End Get
            Set
                _ePointList = Value
            End Set
        End Property

        Public Property PortNameList As ObservableCollection(Of String)
            Get
                Return _portNameList
            End Get
            Set
                _portNameList = Value
            End Set
        End Property

        Public Property EndCharList As ObservableCollection(Of String)
            Get
                Return _endCharList
            End Get
            Set
                _endCharList = Value
            End Set
        End Property

        Public Property IsModbusOk As Boolean
            Get
                Return _isModbusOk
            End Get
            Set
                _isModbusOk = Value
            End Set
        End Property

        Public Property Reason As String
            Get
                Return _reason
            End Get
            Set
                _reason = Value
                EnableSave = Not String.IsNullOrWhiteSpace(_reason)
                RaisePropertyChanged()
            End Set
        End Property

        Public Property EnableSave As Boolean
            Get
                Return _enableSave
            End Get
            Set
                _enableSave = Value
                RaisePropertyChanged()
            End Set
        End Property

        Public Property ApplyCommand As RelayCommand
            Get
                Return _applyCommand
            End Get
            Set
                _applyCommand = Value
            End Set
        End Property

        Public Property Timer As DispatcherTimer
            Get
                Return _timer
            End Get
            Set
                _timer = Value
            End Set
        End Property

        Public Property UpdateTimeCommand As RelayCommand
            Get
                Return _updateTimeCommand
            End Get
            Set
                _updateTimeCommand = Value
            End Set
        End Property

        Public Property EnableAutoSave As Boolean
            Get
                Return _enableAutoSave
            End Get
            Set
                _enableAutoSave = Value
                RaisePropertyChanged()
            End Set
        End Property

        Public Property CancelCommand As RelayCommand
            Get
                Return _cancelCommand
            End Get
            Set
                _cancelCommand = Value
            End Set
        End Property
    End Class
End Namespace